using Unity.Entities;
using UnityEngine;

namespace DOTS.DOD.LESSON5
{
    struct RandomCubeGenerator : IComponentData
    {
        public Entity CubeProtoType;
        public int GenerateTotalCount;
        public int GenerateNumPerTick;
        public float PerTime;
        public bool UseScheduleParallel;
    }

    public class RandomCubeGeneratorAuthoring : MonoBehaviour
    {
        public GameObject NoUseScheduleParallelCube;
        public GameObject UseScheduleParallelCube;

        public int GenerateTotalCount;
        public int GenerateNumPerTick;
        public float PerTime;
        public bool UseScheduleParallel;

        class Baker : Baker<RandomCubeGeneratorAuthoring>
        {
            public override void Bake(RandomCubeGeneratorAuthoring authoring)
            {
                var entity = GetEntity(TransformUsageFlags.None);
                AddComponent(entity, new RandomCubeGenerator()
                {
                    CubeProtoType = authoring.UseScheduleParallel
                        ? GetEntity(authoring.UseScheduleParallelCube, TransformUsageFlags.Dynamic)
                        : GetEntity(authoring.NoUseScheduleParallelCube, TransformUsageFlags.Dynamic),
                    GenerateTotalCount = authoring.GenerateTotalCount,
                    GenerateNumPerTick = authoring.GenerateNumPerTick,
                    PerTime = authoring.PerTime,
                    UseScheduleParallel = authoring.UseScheduleParallel,
                });
            }
        }
    }
}